function out=gobj(w,xi)
% w=randn(dim*3+3,1);
% xi=30;
load fisheriris;


X = meas;[num,dim]=size(X);
y=ones(dim,1);
for i=1:num
    if strcmp(species{i},'setosa')
        y(i) =1;
    elseif strcmp(species{i},'versicolor')
        y(i) =2;
    else
        y(i)=3;
    end
end

C=max(max(abs(X)))*2;

out= w;

idx= y(xi);
for j=1:3
    if idx==j
        if 1-idx*(X(xi,:)*w(1+dim*(j-1):dim*idx)-w(dim*3+j))> 0
            out(1+(j-1)*dim:j*dim)  = out(1+(j-1)*dim:j*dim) - C*X(xi,:)';
            out(3*dim+j) = out(3*dim+j) -C*1;
        end
    else
        if 1+idx*(X(xi,:)*w(1+dim*(idx-1):dim*idx)+w(dim*3+idx))> 0
            out(1+(j-1)*dim:j*dim)  = out(1+(j-1)*dim:j*dim) + C*X(xi,:)';
            out(3*dim+j) = out(3*dim+j) + C*1;
        end
    end
end
